package licode.unisop.authcenter.adapter.web;

import licode.unisop.authcenter.application.executor.CenterRealmQueryExecutor;
import licode.unisop.authcenter.application.info.RealmLookupIn;
import licode.unisop.authcenter.application.info.RealmQueryPageIn;
import licode.unisop.client.inter.HasAuthority;
import licode.unisop.provider.vo.SiPageResult;
import licode.unisop.realm.client.dto.SiRealmDTO;
import licode.unisop.types.AuthConst;
import licode.unisop.unilite.result.UniReturnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 定义统一认证平台中心领域查询相关接口
 *
 * @author licode
 */
@Slf4j
@UniReturnResult
@RestController
@RequestMapping("/uni-center/v1/realm")
public class CenterRealmQueryController {
    @Resource
    private CenterRealmQueryExecutor centerRealmQueryExecutor;

    /**
     * 分页查询领域信息
     */
    @RequestMapping(value = "/query/page", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "realm:query")
    public SiPageResult<SiRealmDTO> queryPage(@RequestBody RealmQueryPageIn req) {
        return centerRealmQueryExecutor.queryPage(req);
    }

    /**
     * 查询指定领域信息
     */
    @RequestMapping(value = "/query/lookup", method = RequestMethod.POST)
    @HasAuthority(roles= AuthConst.SYSTEM_ADMIN, permits = "realm:query")
    public SiRealmDTO lookup(@RequestBody RealmLookupIn req) {
        return centerRealmQueryExecutor.lookup(req);
    }
}
